//
//  RAPDiscoverTableViewController.swift
//  COPYCAT-Weibo
//
//  Created by 闫萌 on 12/27/15.
//  Copyright © 2015 RendezvousAuParadis. All rights reserved.
//

import UIKit

class RAPDiscoverTableViewController: RAPVisitorViewController {

    lazy var searchField: RAPSearchField = {
        // 从nib中读取搜索栏
        let nib = UINib(nibName: "RAPSearchField", bundle: nil)
        let sf = nib.instantiateWithOwner(nil, options: nil).first as! RAPSearchField

        
        return sf
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if !isLogin {
            visitorView.setupVisitorView("visitordiscover_image_message", messageText: "看看这里都关注了谁，每天都有新鲜事。看看这里都关注了谁，每天都有新鲜事。")
            /*
            如果还为登录，则没有必要执行下面的逻辑
            */
            return
        }
        
        // 设置导航栏
        navigationItem.titleView = searchField
        
        tabBarItem.badgeValue = "12"
        
//        TEST()
    }
    
    func TEST() {
        for chdView in (tabBarController?.tabBar.subviews)! {
            if chdView.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                for sChd in chdView.subviews {
                    if sChd.isKindOfClass(NSClassFromString("_UIBadgeView")!) {
                        for ssChd in sChd.subviews {
                            if ssChd.isKindOfClass(NSClassFromString("_UIBadgeBackground")!) {
                                RAPLog("终于找到你，还好没放弃")
                                var outCount: UInt32 = 0
                                let ivar = class_copyIvarList(NSClassFromString("_UIBadgeBackground")!, &outCount)
                                for idx in 0..<outCount {
                                    let x = ivar[Int(idx)]
                                    let nameStr = ivar_getName(x)
                                    RAPLog(NSString(CString: nameStr, encoding: NSUTF8StringEncoding))
                                }
                                
                                ssChd.setValue(UIImage(named: "main_badge"), forKey: "_image")
                            }
                        }
                    }
                }
            }
        }
    }



    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

    /*
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)

        // Configure the cell...

        return cell
    }
    */

    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the specified item to be editable.
        return true
    }
    */

    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the item to be re-orderable.
        return true
    }
    */

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
